package com.ld.control.business.variable.controller;


import com.ld.control.business.equipment.vo.resp.EquipmentRespVo;
import com.ld.control.business.variable.service.VariableService;
import com.ld.control.business.variable.vo.req.VariableReqVo;
import com.ld.control.business.variable.vo.resp.VariableRespVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.common.vo.GeneratePageListVo;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 变量表 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2024-04-23
 */
@Slf4j
@Tag(name = "变量配置相关接口")
@RestController
public class VariableController {

    @Autowired
    private VariableService variableService;

    @GetMapping("/api/centralControl/variable/getPageList")
    @Operation(summary = "变量列表")
    public ResultResponse<GeneratePageListVo<VariableRespVo>> getPageList(
            @RequestParam(required = false) String name,
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "10") Integer size
    ){
        GeneratePageListVo<VariableRespVo> pageList = variableService.getPageList(name, current, size);
        return ResultResponse.success(pageList);
    }

    @PostMapping("/api/centralControl/variable/add")
    @Operation(summary = "添加变量")
    public ResultResponse<ResultResponseEnum> add(@RequestBody VariableReqVo reqVo){
        variableService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/variable/update")
    @Operation(summary = "修改变量")
    public ResultResponse<ResultResponseEnum> update(@RequestBody VariableReqVo reqVo){
        variableService.update(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/variable/deleteById")
    @Operation(summary = "删除变量")
    public ResultResponse<ResultResponseEnum> update(@RequestParam Long id){
        variableService.deleteById(id);
        return ResultResponse.success();
    }

    @GetMapping("/api/centralControl/variable/getById")
    @Operation(summary = "获取变量详情")
    public ResultResponse<VariableRespVo> getById(@RequestParam Long id){
        VariableRespVo variableRespVo = variableService.getById(id);
        return ResultResponse.success(variableRespVo);
    }



}

